<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="author" content="wangbo">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <!-- 如何实现点击一个按钮亮，其余按钮全灭？ -->
    <button>按钮1</button>
    <button>按钮2</button>
    <button>按钮3</button>
    <button>按钮4</button>
    <button>按钮5</button>

    <script>
        //通过for循环首先给所有的按钮点击事件
        var btns = document.getElementsByTagName('button');
        //上面返回的是伪数组，我们对其遍历
        for (var i = 0; i < btns.length; i++) {
            btns[i].onclick = function () {
                //1.首先点击一个，先把所有的按钮变成灰色
                for (var i = 0; i < btns.length; i++) {
                    btns[i].style.backgroundColor = '';
                }
                //2.当前点击的按钮变成粉色,这里写this
                this.style.backgroundColor = 'pink';
            }
        }
    </script>



</body>

</html>